package com.platform.admin.designPattern.statusMachine;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "状态机")
public class StatusMachine<S extends BaseStatus, E extends BaseEvent> {
    
    private final Map<StatusEventPair<S,E>, S> statusEventPairSMap = new HashMap<>();

    @ApiOperation(value = "只接受指定的当前状态下，指定的事件触发，可以到达的指定目标状态")
    public void accept(S sourceStatus, E event, S targetStatus){
        statusEventPairSMap.put(new StatusEventPair<>(sourceStatus, event), targetStatus);
    }

    @ApiOperation(value = "通过源状态和事件，获取目标状态")
    public S getTargetStatus(S sourceStatus, E event){
        return statusEventPairSMap.get(new StatusEventPair<>(sourceStatus, event));
    }
}
